<?php
/*此文件用于平缓重建网站搜索引擎所使用的索引
 * 在平时的使用中索引会自动更新，所以一般不
 * 执行该文件，仅当查询结果与实际有较大出入
 * 时重新生成索引
 * */
header("Content-type: text/html; charset=utf-8");
set_time_limit(0);
require_once ('config.php');
require_once (WEBURL.'/include/conn.php');
require (XunSearchPath.'/sdk/php/lib/XS.php');
require_once (WEBURL.'/login_status_check.php');
if(!checkLogin()){
	$gotopage=base64_encode("all_index_rebuild.php");
	header("Location:admin_login.php?gotopage=".$gotopage);
}
else{	
$xs = new XS('nwsuafcie'); 
$index = $xs->index;
$index->beginRebuild();
echo "正在更新所有文章索引...<br/>";
$sql="select id,article_title,article_main_channel,article_publish_time,article_modify_time,article_from,article_content from search;";
$result=mysql_query($sql);
while($row=mysql_fetch_row($result)){
$data = array(
'id' => $row[0],
'article_title'=> $row[1],
'article_main_channel'=> $row[2],
'article_publish_time'=> $row[3],
'article_modify_time'=> $row[4],
'article_from'=> $row[5],
'article_content'=> $row[6] 
);
// 创建文档对象
$doc = new XSDocument;
$doc->setFields($data);
 
// 添加到索引数据库中
$index->add($doc);
echo "更新文章《".$row[1]."》的索引成功！<br/>";
}
echo "成功更新索引！<br/>";
echo "<a href='javascript:history.back();'>点击此处返回</a>";
$index->endRebuild();
}